package com.ets.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.ets.dao.QuestionDao;
import com.ets.entity.*;

@Repository
public class QuestionDaoImpl extends BaseDaoImpl implements QuestionDao {
	//Get all questions.
	@SuppressWarnings("unchecked")
	@Override
	public List<Question> getAll() {
		String hql="from Question";
		return getSession().createQuery(hql).list();
	}

	@Override
	public void update(Question question) {
		Session session=getSession();
		session.merge(question);
		session.flush();
		session.close();
		
	}

	@Override
	public Question getQuestion(int id) {
		return (Question) getSession().get(Question.class, id);
	}

	@Override
	public void delete(int id) {
		Session session=getSession();
		session.delete(session.get(Question.class, id));
		session.flush();
		session.close();
	}

}
